home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c++ / 466 < prev    next >
Encoding:
Text File  |  1996-08-06  |  2.8 KB  |  96 lines

  1. Path: chronicle.mti.sgi.com!austern
  2. From: mcelroy@ecst.CSUChico.EDU (James Robert McElroy)
  3. Newsgroups: comp.std.c++
  4. Subject: Template linkage
  5. Date: 23 Feb 1996 10:51:30 PST
  6. Organization: California State University, Chico
  7. Approved: austern@isolde.mti.sgi.com
  8. Message-ID: <4gl22l$c7h@charnel.ecst.csuchico.edu>
  9. NNTP-Posting-Host: isolde.mti.sgi.com
  10. X-Original-Date: 23 Feb 1996 18:46:45 GMT
  11. X-Auth: PGPMoose V1.1 PGP comp.std.c++
  12.     iQBVAwUBMS4MxUy4NqrwXLNJAQH2SwH/enRsDTNB67wCUFKD+tMIZ+tpwAidAX8k
  13.     D1JO32U/uxeZUr+XZ9mmSA8tRb9GcZDkY24aj+E1O18Q/KbTESuucg==
  14.     =CKV3
  15. Originator: austern@isolde.mti.sgi.com
  16.  
  17. A question about templates and linkage:
  18.  
  19. When dealing with template functions and template
  20. classes, there are two different entities one has
  21. to be concerned with:  the template definitions
  22. and the template instantiations.  The definitions
  23. are the code we write, e.g.
  24.  
  25. template <class T>
  26. T fubar(T foo)
  27. {
  28.    // whatever
  29. }
  30.  
  31. The instantiations are what the compiler generates:
  32.  
  33. a = fubar(someInt);        // compiler instantiates:
  34.  
  35. int fubar(int foo)
  36. {
  37.    // whatever
  38. }
  39.  
  40. Now, there are four possible combinations for the linkage
  41. of the definitions and instantiations:
  42.  
  43.   Definition      Instantiation
  44.  
  45. 1. Internal         Internal
  46. 2. Internal         external 
  47. 3. External         Internal
  48. 4. External         External
  49.  
  50. With three different compilers, I've run into three different
  51. combinations!!!  (Default behavior, without any switches):
  52.  
  53.  
  54. Template functions (non-class):
  55.  
  56.                  Definition  Instantiation
  57.  
  58. 1.  HP-UX C++ compiler:  External     External  
  59. 2.  Borland 3.1       :  Internal     External
  60. 3.  G++               :  Internal     Internal 
  61.  
  62. Template classes and template class functions:
  63.  
  64. 1. HP-UX C++ compiler :  External      External
  65. 2. Borland 3.1        :  Internal      Internal
  66. 3. G++                :  Internal      Internal
  67.  
  68. HP manages to create external linkage for 
  69. instantiations through the following mechanism:
  70.  
  71. When a template function or class is first
  72. instantiated, a directory directly off the
  73. current directory, called "ptrepository" is
  74. created, in which all template instantiations
  75. are stored.  This has the peculiar effect that
  76. once you create a template instantiation in
  77. one program, you can  call it from another
  78. program without ever defining it in the second
  79. program!!!  (As long as the second program is
  80. in the parent directory of "ptrepository").
  81.  
  82. Has  the ANSI C++ committee come to any sort of
  83. agreement on the linkage of template definitions
  84. and instantiations?
  85. -- 
  86. Jim McElroy
  87. Calif. State Univ., Chico
  88. mcelroy@ecst.csuchico.edu
  89. ---
  90. [ To submit articles: Try just posting with your newsreader.  If that fails,
  91.                       use mailto:std-c++@ncar.ucar.edu
  92.   FAQ:    http://reality.sgi.com/employees/austern_mti/std-c++/faq.html
  93.   Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html
  94.   Comments? mailto:std-c++-request@ncar.ucar.edu 
  95. ]
  96.